package com.yanti.controller;

import com.yanti.domain.ResponseResult;
import com.yanti.filter.LoginUserContextHolder;
import com.yanti.service.UserAnswerDetailsService;
import com.yanti.service.UserDailyStudyTimeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController
@RequestMapping("/dailyStudy")
public class UserDailyStudyTimeController {

    @Resource
    private UserDailyStudyTimeService userDailyStudyTimeService;

//    @GetMapping("/user")
//    public ResponseResult getUserTotalStudyTime(String uid){
//        return ResponseResult.okResult(userDailyStudyTimeService.getTotalStudyTimeInMinutes(uid));
//    }
    /**
     * 获取用户当天学习时间
     * @return 用户当天学习时间（分钟为单位）
     */
    @GetMapping("/todayStudyTime")
    public ResponseResult getUserTodayStudyTime(){
        String uid = Objects.requireNonNull(LoginUserContextHolder.getUserId()).toString();
        // todo 将返回单位改一下，改为秒
        return userDailyStudyTimeService.getTodayStudyTimeInMinutes(uid);
    }

    /**
     * 获取用户总学习时间
     * @return 用户总学习时间（分钟为单位）
     */
    @GetMapping("/totalStudyTime")
    public ResponseResult getUserTotalStudyTime(){
        String uid = Objects.requireNonNull(LoginUserContextHolder.getUserId()).toString();
        // todo 将返回单位改一下，改为秒
        return userDailyStudyTimeService.getTotalStudyTimeInMinutes(uid);
    }
    @DeleteMapping("/deleteTodayStudyTime")
    public ResponseResult deleteTodayStudyTime(){
        String uid = Objects.requireNonNull(LoginUserContextHolder.getUserId()).toString();
        return ResponseResult.okResult(userDailyStudyTimeService.deleteUserDailyStudyTime4Cache(uid));
    }
}
